<admintpl file="header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Doc/index')}">下载资料</a></li>
			<li class="active"><a href="{:U('Doc/add')}" target="_self">添加下载资料</a></li>
		</ul>
		<form action="" method="post" class="form-horizontal js-ajax-forms" id="form-article-add"
			  enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th width="80">文件名称</th>
							<td>
								<input type="text" style="width: 400px;" name="title" id="title" value="" placeholder="请输入文件名称"/>
							</td>
						</tr>
						<tr>
							<th>上传文件</th>
							<td>
								<input type="file" name="upload_thumb" id="upload_thumb"/> &nbsp;
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">添加</button>
				<a class="btn" href="javascript:history.back(-1);">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>

	<script type="text/javascript">
		$("form").submit(function(e){
			var name=$.trim($("#title").val());
			if(name==""){
				layer.msg("文件名称不能为空",{time:1000});
				return;
			}
			// 判断是否选择文件
			var file = $('#upload_thumb');
			if($.trim(file.val()) == ''){
				layer.msg('上传文件不能为空',{time:1000});
				return false;
			}

			var form = new FormData(document.getElementById("form-article-add"));
			form.append("title", name);

			$.ajax({
				url:"{:U('Doc/add_post')}",
				type:"post",
				data:form,
				processData:false,
				contentType:false,
				success:function(result){
					var result=eval("("+result+")");
					if(result.status){
						layer.msg('添加成功',{time:1000},function(){
							location.href = "{:U('Doc/index')}";
						});
					}else{
						layer.msg(result.message);
					}
				},
				error:function(e){
					alert("上传失败");
				}
			});
			return false;
		});
	</script>
</body>
</html>